<!DOCTYPE html>
<script src="../../../resources/js-test.js"></script>
<script>
if (window.testRunner)
    testRunner.keepWebHistory();
</script>
<style>
:link, :visited { all: initial }
#match { background-color: red }
:link #match { background-color: green }
#link + div { color: pink }
</style>
<a id="link">
    <span></span>
    <span>
        <span></span>
        <span id="match"></span>
    </span>
</a>
<div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>
<script>
description("Use descendant invalidation set for :link pseudo class.")

var red = "rgb(255, 0, 0)";
var green = "rgb(0, 128, 0)";

if (window.internals)
    shouldBe("internals.computedStyleIncludingVisitedInfo(match).backgroundColor", "red");

link.offsetTop; // Force recalc.
link.href = "not-visited.html";

if (window.internals) {
    // Ideally, the affected element count should be 2, but there is a _insideLink that
    // causes inheritance to recalc all elements inside <a>.
    shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "5");
    shouldBe("internals.computedStyleIncludingVisitedInfo(match).backgroundColor", "green");
}

</script>
